public class boolean[]
extends Object
GDK enhancements for boolean[].
| Type Params | Return Type | Name and description |
|---|---|---|
|
public boolean |
any()Iterates over the contents of a boolean Array, and checks whether any element is true. |
|
public boolean |
any(Closure<?> predicate)Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element. |
|
public boolean |
asBoolean()Coerces a boolean array to a boolean value. |
|
public List<List<Boolean>> |
chop(int chopSizes)Chops the boolean array into pieces, returning lists with sizes corresponding to the supplied chop sizes. |
|
public boolean |
contains(Object value)Checks whether the array contains the given value. |
|
public Number |
count(Object value)Counts the number of occurrences of the given value inside this array. |
|
public boolean[] |
each(Consumer<Boolean> consumer)Iterates through a boolean[] passing each boolean to the given consumer. |
|
public boolean[] |
eachWithIndex(Closure<?> closure)Iterates through a boolean[], passing each boolean and the element's index (a counter starting at zero) to the given closure. |
|
public boolean |
equals(boolean[] right)Compares the contents of this array to the contents of the given array. |
|
public boolean |
every()Iterates over the contents of a boolean Array, and checks whether every element is true. |
|
public boolean |
every(Closure<?> predicate)Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element. |
|
public boolean |
first()Returns the first item from the boolean array. |
|
public List<Boolean> |
flatten()Flattens an array. |
|
public List<Boolean> |
getAt(Range<?> range)Supports the subscript operator for a boolean array with a range giving the desired indices. |
|
public List<Boolean> |
getAt(IntRange range)Supports the subscript operator for a boolean array with an IntRange giving the desired indices. |
|
public List<Boolean> |
getAt(ObjectRange range)Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices. |
|
public List<Boolean> |
getAt(Collection<?> indices)Supports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices. |
|
public IntRange |
getIndices()Returns indices of the boolean array. |
|
public String |
groovyToString()Returns Groovy's list-like string representation for a boolean array. |
|
public boolean |
head()Returns the first item from the boolean array. |
|
public boolean[] |
init()Returns the items from the boolean array excluding the last item. |
|
public String |
join()Concatenates the string representation of each item in this array. |
|
public String |
join(String separator)Concatenates the string representation of each item in this array, with the given String as a separator between each item. |
|
public boolean |
last()Returns the last item from the boolean array. |
|
public void |
putAt(IntRange range, boolean[] source)A helper method to allow arrays to be set with subscript operators. |
|
public void |
putAt(IntRange range, Iterable<Boolean> source)A helper method to allow arrays to be set with subscript operators. |
|
public boolean[] |
reverse()Creates a new boolean array containing items which are the same as this array but in reverse order. |
|
public boolean[] |
reverse(boolean mutate)Reverses the items in an array. |
|
public boolean[] |
reverseEach(Closure<?> closure)Iterates through a boolean[] in reverse order passing each boolean to the given closure. |
|
public int |
size()Provides arrays with a size method similar to collections.
|
|
public Stream<Boolean> |
stream()Returns a sequential Stream with the specified array as its source. |
|
public boolean[] |
swap(int i, int j)Swaps two elements at the specified positions. |
|
public boolean[] |
tail()Returns the items from the boolean array excluding the first item. |
|
public List<Boolean> |
toList()Converts this array to a List of the same size, with each element added to the list. |
|
public Set<Boolean> |
toSet()Converts this array to a Set, with each unique element added to the set. |
|
public String |
toString()Returns the string representation of the given array. |
| Methods inherited from class | Name |
|---|---|
class Object |
addShutdownHook, any, any, asBoolean, asType, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits |
Iterates over the contents of a boolean Array, and checks whether any element is true.
boolean[] array1 = [false, true]
assert array1.any()
boolean[] array2 = [false]
assert !array2.any()
Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element.
boolean[] array = [true]
assert array.any{ it }
assert !array.any{ !it }
predicate - the closure predicate used for matchingCoerces a boolean array to a boolean value. A boolean array is false if the array is of length 0, and true otherwise.
Chops the boolean array into pieces, returning lists with sizes corresponding to the supplied chop sizes. If the array isn't large enough, truncated (possibly empty) pieces are returned. Using a chop size of -1 will cause that piece to contain all remaining items from the array.
boolean[] array = [false, true, false]
assert array.chop(1, 2) == [[false], [true, false]]
chopSizes - the sizes for the returned piecesChecks whether the array contains the given value.
value - the value being searched for Counts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0).
boolean[] array = [false, true, true]
assert array.count(true) == 2
value - the value being searched forIterates through a boolean[] passing each boolean to the given consumer.
boolean[] array = [false, true, false]
String result = ''
array.each{ result += it.toString()[0] }
assert result == 'ftf'
consumer - the consumer for each booleanIterates through a boolean[], passing each boolean and the element's index (a counter starting at zero) to the given closure.
boolean[] array = [false, true, false]
String result = ''
array.eachWithIndex{ item, index -> result += "$index($item)" }
assert result == '0(false)1(true)2(false)'
closure - a Closure to operate on each booleanCompares the contents of this array to the contents of the given array.
Example usage:
boolean[] array1 = [true, false]
boolean[] array2 = [true, false]
assert array1 !== array2
assert array1.equals(array2)
right - the array being comparedIterates over the contents of a boolean Array, and checks whether every element is true.
boolean[] array1 = [false, true]
assert !array1.every()
boolean[] array2 = [true, true]
assert array2.every()
Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element.
boolean[] array = [true]
assert array.every{ it }
assert !array.every{ !it }
predicate - the closure predicate used for matchingReturns the first item from the boolean array.
boolean[] array = [true, false]
assert array.first() == true
An alias for head(). Flattens an array. This array is added to a new collection.
It is an alias for toList() but allows algorithms to be written which also
work on multidimensional arrays or non-arrays where flattening would be applicable.
boolean[] array = [false, true]
assert array.flatten() == [false, true]
Supports the subscript operator for a boolean array with a range giving the desired indices.
boolean[] array = [false, true, false, true, false, true]
assert array[2..<2] == [] // EmptyRange
assert array[(0..5.5).step(2)] == [false, false, false] // NumberRange
assert array[(1..5.5).step(2)] == [true, true, true] // NumberRange
range - a range indicating the indices for the items to retrieveSupports the subscript operator for a boolean array with an IntRange giving the desired indices.
boolean[] array = [false, false, true, true, false]
assert array[2..3] == [true, true]
assert array[-2..-1] == [true, false]
assert array[-1..-2] == [false, true]
range - an IntRange indicating the indices for the items to retrieveSupports the subscript operator for a boolean array with an ObjectRange giving the desired indices.
boolean[] array = [false, false, true, true, false]
def range = new ObjectRange(2, 3)
assert array[range] == [true, true]
range - an ObjectRange indicating the indices for the items to retrieveSupports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices.
boolean[] array = [false, false, true, true, false]
assert array[2, 3] == [true, true]
assert array[0, 0..1, [1, [-1]]] == [false, false, false, false, false]
indices - a collection of indices for the items to retrieveReturns indices of the boolean array.
boolean[] array = [false, true]
assert array.indices == 0..1
Returns Groovy's list-like string representation for a boolean array.
If disabled, e.g. via -Dgroovy.extension.disable=groovyToString(boolean[]),
the JDK's default array toString() is used instead.
Returns the first item from the boolean array.
boolean[] array = [true, false]
assert array.head() == true
An alias for first().Returns the items from the boolean array excluding the last item.
boolean[] array = [true, false, true]
def result = array.init()
assert result == [true, false]
assert array.class.componentType == result.class.componentType
Concatenates the string representation of each item in this array.
Concatenates the string representation of each item in this array, with the given String as a separator between each item.
separator - a String separatorReturns the last item from the boolean array.
boolean[] array = [true, false, true]
assert array.last() == true
A helper method to allow arrays to be set with subscript operators.
boolean[] from = [true, true, true]
boolean[] to = [false, false, false, false, false]
to[1..3] = from
assert to == [false, true, true, true, false]
range - the subset of the array to setsource - the source array from which new values will comeA helper method to allow arrays to be set with subscript operators. False will be used if the source iterable has insufficient elements.
def from = [true, true, true]
boolean[] to = [false, false, false, false, false]
to[1..3] = from
assert to == [false, true, true, true, false]
range - the subset of the array to setsource - the source array from which new values will comeCreates a new boolean array containing items which are the same as this array but in reverse order.
boolean[] array = [false, true]
assert array.reverse() == [true, false]
Reverses the items in an array. If mutate is true, the original array is modified in place and returned. Otherwise, a new array containing the reversed items is produced.
boolean[] array = [false, true, true]
def yarra = array.reverse(true)
assert array == [true, true, false]
assert yarra == [true, true, false]
assert array === yarra
yarra = array.reverse(false)
assert array !== yarra
assert array == [true, true, false]
assert yarra == [false, true, true]
mutate - true if the array itself should be reversed in place, false if a new array should be createdIterates through a boolean[] in reverse order passing each boolean to the given closure.
boolean[] array = [false, true, true]
String result = ''
array.reverseEach{ result += it }
assert result == 'truetruefalse'
closure - the closure applied on each boolean Provides arrays with a size method similar to collections.
boolean[] array = [true, false, true]
assert array.size() == 3
Returns a sequential Stream with the specified array as its source.
Stream for the arraySwaps two elements at the specified positions.
Example:
assert ([false, true, false, true] as boolean[]) == ([false, false, true, true] as boolean[]).swap(1, 2)
i - a positionj - a positionReturns the items from the boolean array excluding the first item.
boolean[] array = [true, false, true]
def result = array.tail()
assert result == [false, true]
assert array.class.componentType == result.class.componentType
Converts this array to a List of the same size, with each element added to the list.
Converts this array to a Set, with each unique element added to the set.
boolean[] array = [true, false, true]
Set expected = [true, false]
assert array.toSet() == expected
Returns the string representation of the given array.
boolean[] array = [false, true, false]
assert array.toString() == '[false, true, false]'